﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace CPPEI.WorkflowCore.Simulator
{
    /// <summary>
    /// 内存模拟实例存储
    /// </summary>
    public class InstanceStorage : IInstanceStorage
    {
        private List<Instance> _pool = new List<Instance>();

        public Instance Find(Guid id)
        {
            return _pool.SingleOrDefault(p => p.Id == id);
        }

        public PagedList<Instance> FindList(int start, int limit)
        {
            List<Instance> list = _pool.Take(limit).Skip(start).ToList();
            return new PagedList<Instance>(_pool.Count, start, limit, list);
        }

        public void Save(Instance instance)
        {
            if (_pool.SingleOrDefault(p => p.Id == instance.Id) == null)
            {
                _pool.Add(instance);
            }
        }

        public void Remove(Instance instance)
        {
            _pool.Remove(instance);
        }
    }
}
